home *** CD-ROM | disk | FTP | other *** search
- var XXX = function () {
- var out = ''
- if (arguments.length > 1) {
- for (var i = 0;i < arguments.length;i++) {
- out += arguments[i] + " : ";
- }
- }
- else {
- }
- };
-
-
- function flock_getTreeSelection(aTree, aCols, aOpts) {
- if (!aOpts) aOpts = {};
- var indexList = [];
-
- var rangeMin = {};
- var rangeMax = {};
- aTree.view.selection.getRangeAt(0, rangeMin, rangeMax);
- var out = [];
- var rangeCount = aTree.view.selection.getRangeCount();
- XXX('RANGE INIT', rangeMin.value, rangeMax.value);
- XXX('RANGECOUNT', rangeCount);
- for (var j = 0; j < rangeCount; ++j) {
- var dummy = {};
- aTree.view.selection.getRangeAt(j, dummy, rangeMax);
- XXX('RANGE', rangeMin.value, rangeMax.value);
- }
- XXX('RANGE END', rangeMin.value, rangeMax.value);
-
- for (var i = rangeMin.value; i <= rangeMax.value; ++i) {
- if (!aTree.view.selection.isSelected(i)) continue;
- var rowIndex = i;
- var parentIndex = aTree.view.getParentIndex(i);
- var isContainer = aTree.view.isContainer(i);
- if (aOpts['filterChildren']
- && indexList.indexOf(parentIndex) != -1) {
- continue;
- }
- indexList.push(rowIndex);
- var row = {
- rowIndex: rowIndex,
- parentIndex: parentIndex,
- isContainer: isContainer
- };
-
- row["parentIndex"] = aTree.view.getParentIndex(i);
- row["isContainer"] = aTree.view.isContainer(i);
- for (var j = 0; j < aCols.length; ++j) {
- var colName = aCols[j];
- var col = aTree.columns.getNamedColumn(colName);
- row[colName] = aTree.view.getCellText(i, col);
- }
- out.push(row);
- }
- return out;
- }
-
- function flock_getMarkedUpSelection(aEvt, aDropData, aSession){/*{{{*/
- var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService();
- var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
- var topWindow = windowManagerInterface.getMostRecentWindow("navigator:browser");
-
- var data="";
- var node=aSession.sourceNode;
- var serializer = new XMLSerializer();
- var parser = new DOMParser();
-
- var header="Header";
- var label="Label";
- var type="document";
-
- // Text (from input zone or external application)
- if (aDropData.flavour.contentType == "text/unicode") {
- var location = topWindow.document.getElementById('content').mCurrentBrowser.contentWindow.location + "";
- var text = aDropData.data;
- var src;
- if (location.match(/^chrome:\/\/.+/)){
- location = "";
- src = text;
- } else {
- src = "<a href='"+location+"'>"+text+"</a>";
- }
- return { type: "document", header: location, label: text, src: src };
- }
-
- var contentDetector = new nsContentDetector();
- contentDetector.setTarget(node);
-
-
- // Images
- if (contentDetector.onImage) {
- header=node.alt;
- label=contentDetector.imageURL;
- type='image';
- var src='<img src="' + label + '" />';
- return { type: type, header: header, label: label, src: src };
- }
-
- //Not handling files just yet.
- if(aDropData.flavour.contentType=='application/x-moz-file'){
- return null;
- }
-
- //For dragging from outside the browser. Not supported for now.
- if(!node){
- return null;
- }
-
- // XXX('markedselection', node.nodeName.toLowerCase());
- switch(node.nodeName.toLowerCase()){
- //Handle image maps
- case 'area':
- var map='#' + node.parentNode.getAttribute('name');
- var images=topWindow.window._content.document.getElementsByTagName('img');
- dump(images.length + '\n');
- for(i=0; i<images.length; i++){
- dump('IMG: ' + images[i].src + '\n');
- if(images[i].getAttribute('usemap')==map){
- node=images[i];
- }
- }
- if(node.nodeName.toLowerCase()=='area'){
- dump('Could not find image corresponding to map ' + map + '.\n');
- return false;
- }
- //TODO: Normalize paths for node...
- return { type: type, header: header, label: label, src: serializer.serializeToString(node) };
-
- //Big hack. This is for when somebody drags the favicon onto the shelf. Without this, we get the xul source b/c we're using sourceNode.
- case 'image':
- header=topWindow.document.getElementById('content').contentTitle;
- label=topWindow.document.getElementById('content').contentDocument.URL;
- type='link';
- var src='<a href="' + label + '">' + $$('content').contentTitle + '</a>';
- return { type: type, header: header, label: label, src: src };
-
- //Handle flickr photos
- case 'photo':
- var doc = parser.parseFromString(node.photoHTML, "text/xml");
- img_elm=doc.getElementsByTagName('img');
- a_elm=doc.getElementsByTagName('a');
- header=img_elm[0].getAttribute('alt');
- header=header.replace(/%20/g, ' ');
- label=img_elm[0].getAttribute('src');
- return { type: "image", header: header, label: label, src: node.photoHTML };
- // Browser tabs
- case 'tab':
- case 'xul:tab':
- return { type: "link", header: node.label, label: window.top.content.document.location.toString(), src: "" };
- // Can be from the shelf itself (to ignore)
- // or from the favorite manager (to insert)
- // XXX need to find a cleaner way to do all that stuff
- case 'shelficon':
- if (node.type == 'document'){
- return { type: node.type, header: node.url, label: node.title, src: node.src, dragfrom: node.id };
- } else {
- return { type: node.type, header: node.title, label: node.url, src: node.src, dragfrom: node.id };
- }
- case 'treechildren': // ERW: Big hack to get the info I need. Will be better once we have metadata attached to each object we drag
- XXX('node.parentNode.id', node.parentNode.id);
- if (node.parentNode.id == "flock_favoriteView")
- {
- var source = aDropData.data;
- var title = source.split(">")[1].split("<")[0];
- var url = source.split("'")[1];
- return { type: "link", header: title, label: url, src: source };
- } else {
- // for (i in node.parentNode){
- // XXX('treechildren.parentnode->'+i, node.parentNode[i]);
- // }
- }
- default:
- //Handle selections
- var selection = flock.browser.getSelection();
- for (i in node){
- XXX("node."+i, node[i]);
- }
- if(selection.toString().length > 0){
- //XXX('We get the selection ', selection);
- var selection_formatted=select_src(selection);
- title=topWindow.document.getElementById('content').contentTitle;
- if(title.length==0) title = location;
-
- var location = topWindow.document.getElementById('content').mCurrentBrowser.contentWindow.location + "";
- if (location.match(/^chrome:\/\/.+/)) location = "";
-
- //TODO: Normalize paths for selection...
- data = '<blockquote cite="' + location + '">' + selection_formatted.html + "</blockquote>";
- data += '<p class="citation"><cite cite="' + location + '"><a href="' + location + '">' + title + '</a>' + "</cite></p><br/>";
- header=location;
- label=selection;
- return { type: 'document', header: header, label: label, src: data };
- }
- else{
- if(node.nodeName.toString().toLowerCase()=='#text'){
- node=node.parentNode;
- }
-
- //If it's an img, make sure the src attribute is the full path
- if(node.src){
- node.setAttribute('src',node.src);
- type='image';
- label=node.src;
- header=node.src;
- if(node.getAttribute('alt')){
- header=node.getAttribute('alt');
- }
- }
- //If it's a link make sure the href attribute is the full path
- if(node.href){
- node.setAttribute('href',node.href);
- type='link';
- label=node.href;
- header=node.textContent;
- }
- return { type: type, header: header, label: label, src: serializer.serializeToString(node) };
- }
- }
- XXX('flock_getMarkedUpSelection: unable to understand this dropdata!!');
- return aDropData.data;
-
- }/*}}}*/